from option import Option
import stats
import signals
import helpers

def preprocess_time(t):
	if bool(int(Option().config.get('autoaccept_times', 0))):
		process_time(t)
		return
	Option().windowMain.header.set_text(helpers.fmt(t))
	Option().windowMain.xml.get_widget('ButGo').set_label('Accept')
	Option().windowMain.xml.get_widget('ButDiscard').set_sensitive(True)
	Option().windowMain.xml.get_widget('ButPenalty').set_sensitive(True)
	Option().time_pending=True
	signals.emit('timer.preprocess',t)

def process_time(t):
	t=round(t,2)
	Option().windowMain.addScore(t)
	Option().session.process_time(t)
	Option().mode.process_time(t)	
	stats.process_time(t)
	signals.emit('timer.process',t)

	Option().windowMain.refresh()

	prepare()

def prepare():
	Option().windowMain.header.set_text('')
	Option().windowMain.xml.get_widget('ButGo').set_label('GO')
	Option().windowMain.xml.get_widget('ButDiscard').set_sensitive(False)
	Option().windowMain.xml.get_widget('ButPenalty').set_sensitive(False)
	Option().windowMain.xml.get_widget('ButGo').grab_focus()
	Option().time_pending=False
	signals.emit('backend.prepare')

